package com.kantboot.functional.pay.order.module.entity;

import com.kantboot.util.core.jpa.KantbootGenerationType;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.io.Serializable;
import java.util.Date;

@Entity
@Getter
@Setter
@Table(name = "functional_pay_order")
@Accessors(chain = true)
@EntityListeners(AuditingEntityListener.class)
@DynamicUpdate
@DynamicInsert
public class FunctionalPayOrder implements Serializable {

    /**
     * 订单状态：未支付 unpaid
     */
    public static final String STATUS_CODE_UNPAID = "unpaid";

    /**
     * 订单状态：已支付 paid
     */
    public static final String STATUS_CODE_PAID = "paid";

    /**
     * 订单状态：已退款 refunded
     */
    public static final String STATUS_CODE_REFUNDED = "refunded";

    /**
     * 订单状态：已取消 canceled
     */
    public static final String STATUS_CODE_CANCELED = "canceled";

    /**
     * 订单状态：异常 error
     */
    public static final String STATUS_CODE_ERROR = "error";

    /**
     * 主键
     */
    @Id
    @GenericGenerator(name = "snowflakeId",strategy = KantbootGenerationType.SNOWFLAKE)
    @GeneratedValue(generator = "snowflakeId")
    @Column(name = "id")
    private Long id;

    /**
     * 是否已做状态处理
     */
    @Column(name="is_status_processed")
    private Boolean isStatusProcessed;

    /**
     * 是否已做支付校验处理
     */
    @Column(name="is_paid_check_processed")
    private Boolean isPaidAfterCheckProcessed;


    /**
     * 订单金额
     */
    @Column(name="amount")
    private Double amount;

    /**
     * 订单状态，驼峰式
     * 未支付 unpaid
     * 已支付 paid
     * 已退款 refunded
     * 已取消 canceled
     * 异常 error
     */
    @Column(name="status_code")
    private String statusCode;

    /**
     * 支付后校验码
     * 用于校验支付是否正确
     */
    @Column(name="is_paid_after_check_success")
    private Boolean isPaidAfterCheckSuccess;

    /**
     * 校验失败原因编码
     * 出于国际化与查找原因的考虑，使用编码
     */
    @Column(name="paid_check_fail_reason_code")
    private String paidAfterCheckFailReasonCode;

    /**
     * 校验失败原因描述
     * 如果非国际化项目，可以直接使用文字
     */
    @Column(name="paid_check_fail_reason_description")
    private String paidAfterCheckFailReasonDescription;

    /**
     * 产品编码
     * 用于区分不同的产品
     * 例如：oMoney
     * 例如：oVip
     */
    @Column(name="product_code")
    private String productCode;

    /**
     * 描述
     */
    @Column(name="description")
    private String description;

    /**
     * 货币
     * 例如：CNY
     * 例如：USD
     */
    @Column(name="currency")
    private String currency;

    /**
     * 支付方式编码
     * 例如：wechatPay
     * 例如：alipay
     */
    @Column(name="pay_method_code")
    private String payMethodCode;

    /**
     * 订单发起人的用户id
     */
    @Column(name="user_id")
    private Long userId;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "gmt_create")
    private Date gmtCreate;

    /**
     * 最后一次修改时间
     */
    @LastModifiedDate
    @Column(name = "gmt_modified")
    private Date gmtModified;


}
